package com.authine.cloudpivot.web.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.exception.PortalException;
import com.authine.cloudpivot.web.api.service.ResourcesDistributionService;
import com.authine.cloudpivot.web.api.view.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@Api(description = "外企德科相关接口", tags = "任务分发")
@RestController
@RequestMapping("/api/resourcesDistribution")
@Slf4j
@Validated
public class ResourcesDistributionController extends BaseController {

    @Autowired
    public ResourcesDistributionService resourcesDistributionService;


    /**
     * @Description : 任务分发：招聘或店检，提醒执行经理填写任务提交表单
     * @param ： storeNum
     * @author : Liun
     * @date : 2020/4/24
     */
    @ApiOperation(value = "任务分发：招聘或店检，提醒督导" )
    @GetMapping("/remindEManager")
    @ResponseBody
    public ResponseResult<?> remindEManager(String objectId,String projectNames,String takeType,String task,String distribute){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            resourcesDistributionService.remindEManager(objectId,projectNames,takeType,task,distribute);
            json.put("message","推送任务提交数据成功！");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "推送任务提交数据失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }



   /**
    * @Description : 根据当前人员(执行经理)，当前项目，获取大区
    * @param ： userID
    * @param ： projectNames
    * @author : Liun
    * @date : 2020/4/24
    */
    @ApiOperation(value = "根据当前人员，当前项目，获取大区" )
    @GetMapping("/findAreaByEManager")
    @ResponseBody
    public ResponseResult<?> findAreaByEManager(String projectNames,String userID){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            String area=resourcesDistributionService.findAreaByEManager(projectNames,userID);
            json.put("area",area);
            json.put("message","查找大区数据成功！");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "查找大区数据失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }






}
